home *** CD-ROM | disk | FTP | other *** search
/ Hottest 6 / Hottest 6 (1996)(PDSoft)[!].iso / software / emulators / vgb_amiga_0.3 / common.h < prev    next >
Text File  |  1978-11-24  |  3KB  |  111 lines

  1. /** VGB: portable GameBoy emulator ***************************/
  2. /**                                                         **/
  3. /**                        Common.h                         **/
  4. /**                                                         **/
  5. /** This file contains parts of the drivers which are       **/
  6. /** common for both Unix/X and MSDOS.                       **/
  7. /**                                                         **/
  8. /** Copyright (C) Marat Fayzullin 1995                      **/
  9. /**     You are not allowed to distribute this software     **/
  10. /**     commercially. Please, notify me, if you make any    **/   
  11. /**     changes to this file.                               **/
  12. /*************************************************************/
  13.  
  14.  
  15. /****************************************************************/
  16. /*** Refresh a line.                                          ***/
  17. /****************************************************************/
  18. void RefreshLine(byte Y)
  19. {
  20.   register byte Offset,Mask,*P,*T,*R,D0,D1,X1,X2;
  21.  
  22.   R=XBuf+WIDTH*Y;
  23.     
  24.   if((LCDCONT&0x81)!=0x81)
  25.     for(X1=0;X1<WIDTH;X1++) *R++=Palette[0];
  26.   else
  27.   {
  28.     Offset=Y+SCROLLY;
  29.     T=BgdTab+((word)(Offset&0xF8)<<2);
  30.     Offset=(Offset&0x07)<<1;
  31.       
  32.     D0=*(T+(SCROLLX>>3));
  33.     if(~LCDCONT&0x10) D0+=0x80;
  34.     P=ChrGen+(D0<<4)+Offset;
  35.     D0=*P++;D1=*P;Mask=0x80>>(SCROLLX&0x07);   
  36.   
  37.     X1=SCROLLX;X2=SCROLLX+WIDTH;
  38.     while(X1!=X2)
  39.     {
  40.       *R=Palette[BPal[D0&Mask? (D1&Mask? 3:1):(D1&Mask? 2:0)]];
  41.       R++;X1++;
  42.       if(!(Mask>>=1))
  43.       {
  44.         D0=*(T+(X1>>3));
  45.         if(~LCDCONT&0x10) D0+=0x80;
  46.         P=ChrGen+(D0<<4)+Offset;
  47.         D0=*P++;D1=*P;Mask=0x80;
  48.       }
  49.     }
  50.   }
  51.       
  52.   X1=WNDPOSX-7;X2=LCDCONT&0x02;
  53.   if(((LCDCONT&0xA0)==0xA0)&&(WNDPOSY<Y)&&(X1<WIDTH))
  54.   {
  55.     R-=WIDTH-X1;
  56.     Offset=Y-WNDPOSY;
  57.     T=WndTab+((word)(Offset&0xF8)<<2);
  58.     Offset=(Offset&0x07)<<1;
  59.      
  60.     D0=*T+0x80;
  61.     P=RAM+0x8800+((word)D0<<4)+Offset;
  62.     D0=*P++;D1=*P;Mask=0x80;   
  63.   
  64.     for(;X1<WIDTH;X1++,R++)
  65.     {
  66.       *R=Palette[BPal[D0&Mask? (D1&Mask? 3:1):(D1&Mask? 2:0)]];
  67.       if(!(Mask>>=1))
  68.       {
  69.         D0=*(++T)+0x80;
  70.         P=RAM+0x8800+((word)D0<<4)+Offset;
  71.         D0=*P++;D1=*P;Mask=0x80;
  72.       }
  73.     }
  74.   }
  75. }
  76.  
  77.  
  78. /****************************************************************/
  79. /*** Refresh sprites.                                         ***/
  80. /****************************************************************/
  81. void RefreshSprites()
  82. {
  83.   register byte *P,*T,*R,*S,I,J,K,N,D0,D1;
  84.   register offset DX,DY;
  85.  
  86.   N=LCDCONT&0x04? 16:8;
  87.  
  88.   for(S=RAM+0xFE9C,J=40;J;S-=4,J--)
  89.     if(S[0]&&(S[0]<160)&&(S[1]>=8)&&(S[1]<=152))
  90.     {
  91.       if(S[0]<16) { D0=0;K=16-S[0];I=(K<N)? N-K:0; }
  92.       else        { D0=S[0]-16;K=0;I=(160-S[0]<N)? 160-S[0]:N; }
  93.       P=XBuf+D0*WIDTH+S[1]-(S[3]&0x20? 1:8);
  94.       DX=(S[3]&0x20? -1:1);DY=2;
  95.       if(S[3]&0x40) { DY=-DY;K=N-K-1; }
  96.       T=RAM+0x8000+((long)((N>8)? S[2]&0xFE:S[2])<<4)+(K<<1);
  97.       R=(S[3]&0x10)? SPal1:SPal0;
  98.  
  99.       for(;I;I--,P+=WIDTH-(DX<<3),T+=DY)
  100.         for(K=0x80,D0=*T,D1=*(T+1);K;K>>=1,P+=DX)
  101.           if((D0|D1)&K) *P=Palette[R[D0&K? (D1&K? 3:1):(D1&K? 2:0)]];
  102.     }
  103. }
  104.  
  105.  
  106. /****************************************************************/
  107. /*** Display the screen buffer.                               ***/
  108. /****************************************************************/
  109. void RefreshScreen() { PutImage(); }
  110.  
  111.